/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import DTO.HoaDon_DTO;
import java.sql.ResultSet;

/**
 *
 * @author Lenh Ho Xung
 */
public class HoaDon_DAO {

    private static String sqlString;
    private static MSSQLConnect cn;
    private static ResultSet rs;

    public static String laymaMax() throws Exception {
        String mahdMax = new String();
        sqlString = "SELECT TOP 1 MaHoaDon FROM HoaDon ORDER BY MaHoaDon DESC";
        try {
            cn = new MSSQLConnect();
            rs = cn.excuteQuery(sqlString);
            while (rs.next()) {
                mahdMax = rs.getString("MaHoaDon");
            }
        } catch (Exception e) {
            throw new Exception("Không thể lấy mã max");

        } finally {
            cn.Close();
        }
        return mahdMax;

    }
        public static int Insert(HoaDon_DTO p) throws Exception {
        int n;
        sqlString = "INSERT INTO HoaDon (MaHoaDon, MaKhach , NgayThanhToan, TriGia , PhiThuePhong, PhiDichVu, PhiDatTiec, PhiHuHai ) VALUES('"
                + p.getMahoaDon() + "','"
                + p.getMaKhach() + "','"
                + p.getNgaythanhToan() + "','"
                + p.getTriGia() + "','"
                + p.getPhiThuePhong() + "','"
                + p.getPhiDichVu() + "','"
                + p.getPhiDatTiec() + "','"
                + p.getPhiHuHai() + "')";

        //Kết nối CSDL
        try {
            cn = new MSSQLConnect();
            n = cn.executeUpdate(sqlString);
        } catch (Exception e) {
            System.out.println(e.toString());
            throw new Exception("Không thể thêm vào cơ sơ dữ liệu");
        } finally {
            cn.Close();
        }
        return n;
    }
}
